package com.frain.springcloud.user.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.frain.springcloud.user.entity.UserInfo;
import com.frain.springcloud.util.Collections3;

public class UserMapUtil {

    private static Map<String, UserInfo> map = new HashMap<>();

    public static void addUserInfo(String openId, UserInfo userInfo) {

        if (StringUtils.isNoneBlank(openId) && userInfo != null) {
            map.put(openId, userInfo);

        }

    }

    public static UserInfo getUser(String openId) {
        if (!Collections3.isEmpty(map) && map.containsKey(openId)) {
            return map.get(openId);
        }
        return UserInfo.defaultUser(openId);
    }

}
